<html>
  <head><title>Transaction, Datasource and JNDI Test</title></head>

  <body>
    <h1>JettyPlus Transaction, Datasource and JNDI  Test</h1>

<A HREF="test.jsp">Skip to the demo</A>

<H2>Background to the demo</H2>

JettyPlus integrates a number of valuable J2EE features with the core Jetty server: 
 UserTransactions, Datasources and JNDI lookups.

This demonstration illustrates programmatic JNDI lookups of
<b><code>env</code></b> and <b><code>resource-env</code></b> values specified in the
<b><code>web.xml</code></b> descriptor, connecting to a a DataSource, and
using UserTransactions to bracket increments to an integer value
stored in the DataSource.
<P>

The demo's web.xml file contains the following environment entries:

<table width="70%">
<tr>
<td width="10%">
&nbsp;
</td>
<td>
<pre>
<font size=-1>
<code>
&lt;web-app&gt;
<font color="blue">
  &lt;!-- Set up the resource-env-ref for the DataSource --&gt;
</font>
  &lt;resource-env-ref&gt;
    &lt;description&gt;
      DB Connection
    &lt;/description&gt;
    &lt;resource-env-ref-name&gt;
      jdbc/myDB
    &lt;/resource-env-ref-name&gt;
    &lt;resource-env-ref-type&gt;
      javax.sql.DataSource
    &lt;/resource-env-ref-type&gt;
  &lt;/resource-env-ref&gt;
<font color="blue">
  &lt;!-- Set up a couple of env-entries  --&gt;
</font>
  &lt;env-entry&gt;
    &lt;env-entry-name&gt;
       select
    &lt;/env-entry-name&gt;
    &lt;env-entry-value&gt;
       select id, foo from testdata
    &lt;/env-entry-value&gt;
    &lt;env-entry-type&gt;
       java.lang.String
    &lt;/env-entry-type&gt;
  &lt;/env-entry&gt;
  &lt;env-entry&gt;
    &lt;env-entry-name&gt;
       update
    &lt;/env-entry-name&gt;
    &lt;env-entry-value&gt;
       update testdata set foo=? where id=1
    &lt;/env-entry-value&gt;
    &lt;env-entry-type&gt;
       java.lang.String
    &lt;/env-entry-type&gt;
  &lt;/env-entry&gt;
&lt;/web-app&gt;
</code>
</pre>
</font>
<b><i>Application web.xml descriptor</i></b>
</td>
</tr>
</table>


<BR>
<BR>

The relevant sections of the jetty xml configuration file are:
<table width="70%">
<tr>
<td width="10%">
&nbsp;
</td>
<td align=left valign=top>
<font size="-1">
<pre>
<code>
<font color="blue">
&lt;!-- =============================================================== --&gt;
&lt;!-- Configure the JettyPlus Server                                  --&gt;
&lt;!-- =============================================================== --&gt;
</font>
&lt;Configure class=<b>"org.mortbay.jetty.plus.Server"</b>&gt;

<font color="blue">
  &lt;!-- =============================================================== --&gt;
  &lt;!-- Configure a Log4J log sink                                      --&gt;
  &lt;!-- =============================================================== --&gt;
</font>
  &lt;Call name="instance" class="org.mortbay.util.Log"&gt;
    &lt;Call name="disableLog"/&gt;
    &lt;Call name="add"&gt;
      &lt;Arg&gt;
        &lt;New class="org.mortbay.util.log4j.Log4jSink"&gt;
          &lt;Call name="start"/&gt;
        &lt;/New&gt;
      &lt;/Arg&gt;
    &lt;/Call&gt;
  &lt;/Call&gt;



<font color="blue">
  &lt;!-- =============================================================== --&gt;
  &lt;!-- Add a transaction manager and datasources                       --&gt;
  &lt;!-- =============================================================== --&gt;
</font>
  &lt;Call name="addService"&gt;
    &lt;Arg&gt;
      &lt;New class="org.mortbay.jetty.plus.JotmService"&gt;
        &lt;Set name="Name"&gt;TransactionMgr&lt;/Set&gt;
        <font color="blue"> &lt;!-- set up a pooled DataSource --&gt;</font>
         &lt;Call name="addPooledDataSource"&gt;
             &lt;Arg&gt;jdbc/myDB&lt;/Arg&gt;   <font color="blue"&lt;!-- client lookup jndi name of datasource  --&gt;</font>
             <font color="blue">&lt;!-- set up the datasource --&gt;</font>
             &lt;Arg&gt;
               <font color="blue">
               &lt;!-- Uncomment one of the following types of XADataSource        --&gt;
               &lt;!-- according to your type of database:                         --&gt;
               &lt;!-- New class="org.enhydra.jdbc.sybase.SybaseXADataSource"      --&gt;
               &lt;!-- New class="org.enhydra.jdbc.informix.InformixXADataSource"  --&gt;
               &lt;!-- New class="org.enhydra.jdbc.oracle.OracleXADataSource"      --&gt;
               </font>
               &lt;New class="org.enhydra.jdbc.standard.StandardXADataSource"&gt;
                 &lt;Set name="DriverName"&gt;org.hsqldb.jdbcDriver&lt;/Set&gt;
                 &lt;Set name="Url"&gt;jdbc:hsqldb:extra/etc/tmtest&lt;/Set&gt;
                 &lt;Set name="User"&gt;sa&lt;/Set&gt;
                 &lt;Set name="Password"&gt;&lt;/Set&gt;
                 <font color="blue">
                 &lt;!-- Uncomment to setup isolation level as required            --&gt;
                 </font>
                 &lt;!--
                 &lt;Set name="TransactionIsolation"&gt;&lt;Get class="java.sql.Connection" name="TRANSACTION_SERIALIZABLE"/&gt;&lt;/Set&gt; 
                 --&gt;
               &lt;/New&gt;
             &lt;/Arg&gt;
             <font color="blue">&lt;!-- set up a pool for the datasource --&gt;</font>
             &lt;Arg&gt;
               &lt;New class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"&gt;
                 &lt;Arg type="Integer"&gt;4&lt;/Arg&gt;          <font color="blue">&lt;!-- initial size of pool --&gt;</font>     
                 &lt;Set name="MinSize"&gt;4&lt;/Set&gt;                
                 &lt;Set name="MaxSize"&gt;15&lt;/Set&gt; 
                 <font color="blue">&lt;!-- Uncomment to setup other pool params as required          --&gt;</font>
                 &lt;!--
                 &lt;Set name="SleepTime"&gt;10&lt;/Set&gt;
                 &lt;Set name="LifeTime"&gt;10&lt;/Set&gt;
                 &lt;Set name="DeadLockMaxWait"&gt;10&lt;/Set&gt;
                 &lt;Set name="DeadLockRetryWait"&gt;10&lt;/Set&gt;
                 &lt;Set name="LoginTimeout"&gt;10&lt;/Set&gt;
                 &lt;Set name="Debug" type="boolean"&gt;true&lt;/Set&gt;
                 --&gt;
               &lt;/New&gt;
             &lt;/Arg&gt;               
        &lt;/Call&gt;
     &lt;/New&gt;
   &lt;/Arg&gt;
  &lt;/Call&gt;



 
&lt;/Configure&gt;
</code>
</pre>
</font> 
 <b><i>jettyplus.xml configuration file</i></b>
</td>
</tr>
</table>
</center>
<P>
Notice particularly that it is the JettyPlus server class
org.mortbay.jetty.<b>plus</b>.Server being configured, not the
normal Jetty server (org.mortbay.jetty.Server).
<P>
Note also that a log4J log sink must be configured. You must
specify the location of the log4j configuration file on the run
line. For this demo, this is located in the
<code>org.mortbay.jetty.plus.resource.jar</code> file, the source of which is in <code>$jetty.home/extra/plus/resources/log4j.xml</code>.
<P>
Now, you're ready to <A HREF="/jettyplus/test.jsp">try the demo</A>.

  </body>
</html>
